package com.yangjun.utils;

import java.io.IOException;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.JsonParseException;

import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JSONUtils {
      private static ObjectMapper    objectMapper      = new ObjectMapper();

      public static String objToStr(Object o) throws JsonGenerationException,
                  JsonMappingException, IOException {
             return objectMapper.writeValueAsString(o);
      }

      public static <T> T strToObj(String jsonStr, Class<T> classz)
                   throws JsonParseException, JsonMappingException, IOException {
             return (T) objectMapper.readValue(jsonStr, classz);
      }
}